/*
 * @Author: zhuxiaoyi
 * @Date: 2023-05-11 15:18:46
 * @LastEditor: zhuxiaoyi
 * @LastEditTime: 2023-07-09 20:30:58
 * @Description:
 */
import { defineStore } from "pinia";
import { ref, reactive } from "vue";

interface Iuser {
  avatar?: string;
  deptId?: string;
  email?: string;
  fullName?: string;
  id?: string;
  nation?: string;
  passwd?: string;
  phone?: string;
  sex?: string;
  unitId?: string;
  userName?: string;
  userRole?: string;
}

export const useUserStore = defineStore({
  id: "user",
  state: () => {
    let userInfo: Iuser = reactive({});
    const setUserInfo = function (info: Iuser) {
      userInfo.avatar = info.avatar;
      userInfo.deptId = info.deptId;
      userInfo.email = info.email;
      userInfo.fullName = info.fullName;
      userInfo.id = info.id;
      userInfo.nation = info.nation;
      userInfo.passwd = info.passwd;
      userInfo.phone = info.phone;
      userInfo.sex = info.sex;
      userInfo.unitId = info.unitId;
      userInfo.userName = info.userName;
      userInfo.userRole = info.userRole;
    };
    return {
      userInfo,
      setUserInfo,
    };
  },
  // 开启数据缓存
  persist: {
    enabled: true,
    strategies: [
      {
        key: "user", //设置存储的key  全部储存
        storage: localStorage,
        // paths: ["id"], //指定要长久化的字段  选择储存
      },
    ],
  },
});
